package com.yuebanmaoshare.file.controller;

import com.yuebanmaoshare.file.common.result.RestResult;
import com.yuebanmaoshare.file.domain.Favorite;
import com.yuebanmaoshare.file.service.FavoriteService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Tag(name = "收藏管理")
@RestController
@RequestMapping("/favorite")
public class FavoriteController {
    public static final String CURRENT_MODULE = "收藏管理";
    
    @Resource
    private FavoriteService favoriteService;

    @Operation(summary = "获取收藏列表", tags = {"收藏管理"})
    @GetMapping("/list")
    public RestResult<List<Favorite>> getFavoriteList(@RequestParam(value = "userId") String userId) {
        List<Favorite> favoriteList = favoriteService.getFavoriteList(userId);
        return RestResult.success().data(favoriteList);
    }

    @Operation(summary = "添加收藏", tags = {"收藏管理"})
    @PostMapping("/add")
    public RestResult<Boolean> addFavorite(@RequestBody Map<String, String> params) {
        String userId = params.get("userId");
        String fileId = params.get("fileId");
        boolean result = favoriteService.addFavorite(userId, fileId);
        return RestResult.success().data(result);
    }

    @Operation(summary = "取消收藏", tags = {"收藏管理"})
    @DeleteMapping("/remove")
    public RestResult<Boolean> removeFavorite(@RequestBody Map<String, String> params) {
        String userId = params.get("userId");
        String fileId = params.get("fileId");
        boolean result = favoriteService.removeFavorite(userId, fileId);
        return RestResult.success().data(result);
    }

    @Operation(summary = "检查是否已收藏", tags = {"收藏管理"})
    @GetMapping("/check")
    public RestResult<Boolean> checkFavorite(@RequestParam(value = "userId") String userId, @RequestParam(value = "fileId") String fileId) {
        boolean result = favoriteService.isFavorite(userId, fileId);
        return RestResult.success().data(result);
    }
} 